package com.Tread.pool;

import java.util.HashMap;
import java.util.concurrent.*;

public class ScheduleTest {
    public static void main(String[] args) throws InterruptedException {
        ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(2);
        ScheduledFuture<?> schedule = executor.scheduleWithFixedDelay(new Task(1), 2,2, TimeUnit.SECONDS);
        HashMap<String, ScheduledFuture<?>> FutureMap = new HashMap<>();

        FutureMap.put("1", schedule);

        ScheduledFuture<?> schedule1 = executor.scheduleWithFixedDelay(new Task(2),2L ,2L, TimeUnit.SECONDS);
        FutureMap.put("2",schedule1);

        Thread.sleep(5000);

        schedule.cancel(true);
        schedule1.cancel(true);



    }
}

class Task implements Runnable {
    private int i;
    public Task() {
    }

    public Task(int i) {
        this.i = i;
    }



    @Override
    public void run() {
        int j = 0;

            System.out.println(i + " >>>");
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
